<?php
// 应用公共文件

use think\facade\Env;

if (!function_exists('get_allow_file_type')) {
    /**
     * 获取允许文件类型配置
     */
    function get_allow_file_type()
    {
        $allowImgTypeConfig = array_fill_keys(explode(",", Env::get('project.img_type')), 1);
        $allowFileTypeConfig = array_fill_keys(explode(",", Env::get('project.file_type')), 3);
        $allowVideoTypeConfig = array_fill_keys(explode(",", Env::get('project.video_type')), 2);
        return array_merge($allowImgTypeConfig, $allowFileTypeConfig, $allowVideoTypeConfig);
    }
}

if(!function_exists('from_content_type')){
    /**
     * 获取文件真实类型
     */
    function from_content_type(string $contentType)
    {
        $allowFileType = get_allow_file_type();
        return $allowFileType[$contentType] ?? null;
    }
}
